#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** generate(int numRows, int* returnSize, int** returnColumnSizes) {
    *returnColumnSizes = malloc(sizeof(int) * numRows);
    *returnSize = numRows;
    int** arr = malloc(sizeof(int*) * numRows);
    int i = 0;
    for (i = 0; i < numRows; i++)
    {
        arr[i] = malloc(sizeof(int) * (i + 1));
        (*returnColumnSizes)[i] = i + 1;
        arr[i][0] = arr[i][i] = 1;
        int j = 0;
        for (j = 0; j <= i; j++)
        {
            if (i == j || j == 0)
                arr[i][j] = 1;
            else
            {
                arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
            }
        }
    }
    return arr;
}